package com.example.shop.merchant.dto;

import com.example.shop.common.bo.maplocation.Location;
import com.example.shop.pojo.Merchant;
import com.example.shop.pojo.User;
import com.fasterxml.uuid.Generators;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.File;

@Data
public class RegisterParam {

    private MultipartFile avatarFile;
    private String name;
    @NotEmpty
    private String introduction;
    //商家所在位置
    @NotNull
    private Location location;
    //商家的详细地址
    @NotEmpty
    private String detailedAddress;
    //商家号
    @NotEmpty
    private String account;
    //密码
    private String password;

    public Merchant toMerchant(){
        Merchant merchant = new Merchant();
        merchant.setMerchantId(Generators.timeBasedGenerator().generate().node());
        merchant.setMerchantName(name);
        merchant.setMerchantIntroduction(introduction);
        merchant.setMerchantLongitude(location.getLng());
        merchant.setMerchantLatitude(location.getLat());
        merchant.setMerchantDetailedAddress(detailedAddress);
        merchant.setMerchantQualityGrade(5);
        merchant.setMerchantAccount(account);
        merchant.setMerchantPassword(password);
        merchant.setMerchantResourceDir(Merchant.RESOURCE_ROOT_DIR + account + File.separator);
        return merchant;
    }

}
